<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<title>选择市区</title>
		<link rel="stylesheet" href="../../css/amazeui.min.css">
		<link rel="stylesheet" href="css/app.css">
		<style>
		</style>
	</head>
	<body>
	
	<div id='header' class="am-g am-topbar-fixed-top" >
		<div  onclick="api.closeWin();"  class="am-u-sm-2" style="margin-top:12px;padding-left: 17px">
			<img  src="images/arr-l.png" style="height:14px;height: 18px;"/>
		</div>
		<div class="am-u-sm-8 til" style="margin-top:13px;text-align:center;">
			<h1>选择市区</h1>
		</div>
		<div class="am-u-sm-2" style="font-size: 20px;margin-top:10px;color:white;text-align:center;"></div>
	</div>
		
		
	<div class="am-g" style="margin-top:50px;" id="list">
	
	</div>
		
	</body>
	
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript">
		var province = '';
		var city = '';
	
		apiready = function() {
			loadData();
		};
		
		function loadData(){
		    do_ajax('/app/getprovince','get',{},function(ret,err){
		    	  api.hideProgress();
		    	  
				  if(ret){
		                var list = ret;
					    var dataHtml = '';
					    if(list.length>0){
					       for(var i=0;i<list.length;i++){
						        dataHtml += '<div class="am-u-sm-12"  onclick="selectProvince(\''+list[i].name+'\')"  style="margin: 0px;background: white;padding:10px;border-bottom:1px solid #eaedf1;">'
					    		    dataHtml += '<span style="font-weight:bold;" >'+list[i].name+'</span>';
					            dataHtml += '</div>';
					       }
					    }else{
					       dataHtml += '<div  class="am-u-sm-12" style="margin-top:10px;text-align:center">暂无省数据...</div>'
					    }
                              
				        $api.html($api.byId('list'), dataHtml);
						
				       }else{
				            api.alert({
					            msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)
					        });
				       }
			   });
		};
		
		//选择省
		function selectProvince(name){
			province = name;
			
			do_ajax('/app/getcity?province='+province,'get',{},function(ret,err){
		    	api.hideProgress();
		    	  
				if(ret){
		        	var list = ret;
					var dataHtml = '';
					if(list.length>0){
						for(var i=0;i<list.length;i++){
							dataHtml += '<div class="am-u-sm-12"  onclick="selectCity(\''+list[i].name+'\')"  style="margin: 0px;background: white;padding:10px;border-bottom:1px solid #eaedf1;">'
					    	dataHtml += '<span style="font-weight:bold;" >'+list[i].name+'</span>';
					        dataHtml += '</div>';
					    }
					}else{
						dataHtml += '<div  class="am-u-sm-12" style="margin-top:10px;text-align:center">暂无市数据...</div>'
					}
                              
				    $api.html($api.byId('list'), dataHtml);
						
				}else{
					api.alert({
						msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)
					});
				}
			});
		};
		
		//选择省
		function selectCity(name){
			city = name;
			
			//发送选择城市事件
			api.sendEvent({
			    name: 'selectCity',
			    extra: city                              
			});
		
			api.closeWin();
		}
		
	</script>
</html>